<?php

namespace App\Http\Controllers\Api\V1;

use App\Enums\ResponseCode;
use App\Exceptions\ApiExceptions;
use App\Http\Controllers\Api\AbstractApiController;
use App\Http\Resources\JobpositionSingDetailResource;
use App\Http\Resources\JobpositionSingListResource;
use App\Services\Jobposition\JobpositionService;
use App\Services\Jobposition\SignUpService;
use App\Services\Search\SearchService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class SignUpController extends AbstractApiController
{
    /**
     * 报名列表
     * @param SignUpService $service
     * @return JsonResponse
     */
    public function index(SignUpService $service): JsonResponse
    {
        //记录搜索记录
        $result = $service->list(user_id: auth('api')->id());
        return $this->success(trans("success"), ResponseCode::OK, new JobpositionSingListResource($result));
    }

    public function detail(Request $request, SignUpService $service): JsonResponse
    {
        $input = $request->validate([
            'id' => 'required|int|min:1',
        ]);
        $result = $service->detail(auth('api')->id(), $input['id']);
        return self::success(trans("success"), ResponseCode::OK, new JobpositionSingDetailResource($result));
    }
}